package com.controller;

import com.common.Result;
import com.entity.Article;
import com.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * User的路由接口服务
 * 
 * @author 
 *
 */
@RestController
@RequestMapping("pcApi")
public class ArticleController {

	/** UserService服务 */
	@Autowired
	private ArticleService articleService;


	/**
	 * 分页查询
	 * @param bean
	 * @return
	 */
	@ResponseBody
	@PostMapping(value = "/article/create", produces = {"application/json;charset=UTF-8"})
	public Result create(@RequestBody Article bean){
		return articleService.create(bean);
	}

	/**
	 * 修改数据
	 * @param bean
	 * @return
	 */
	@ResponseBody
	@PostMapping(value = "/article/update", produces = {"application/json;charset=UTF-8"})
	public Result update(@RequestBody Article bean) {
		return articleService.update(bean);
	}

	/**
	 * 通过id查询User数据的方法
	 * @param id
	 * @return
	 */
	@ResponseBody
	@PostMapping(value = "/article/{id}", produces = {"application/json;charset=UTF-8"})
	public Article findOne(@PathVariable(name="id") int id) {
		return articleService.findOne(id);
	}

	/**
	 * 分页查询
	 * @param bean
	 * @return
	 */
	@ResponseBody
	@PostMapping(value = "/article/index", produces = {"application/json;charset=UTF-8"})
	public Result index(@RequestBody Article bean){
		return articleService.index(bean);
	}

    /**
     * 根据userId分页查询
     * @param bean
     * @return
     */
    @ResponseBody
    @PostMapping(value = "/article/indexByUserIdAndPublic", produces = {"application/json;charset=UTF-8"})
    public Result indexByUserIdAndPublic(@RequestBody Article bean){
        return articleService.indexByUserIdAndPublic(bean);
    }

	/**
	 * 根据userId分页查询
	 * @param bean
	 * @return
	 */
	@ResponseBody
	@PostMapping(value = "/article/indexByUserId", produces = {"application/json;charset=UTF-8"})
	public Result indexByUserId(@RequestBody Article bean){
		return articleService.indexByUserId(bean);
	}

    /**
     * 根据topicId分页查询
     * @param bean
     * @return
     */
    @ResponseBody
    @PostMapping(value = "/article/indexByTopicId", produces = {"application/json;charset=UTF-8"})
    public Result indexByTopicId(@RequestBody Article bean){
        return articleService.indexByTopicId(bean);
    }

	/**
	 * 推荐文章
	 * @param
	 * @return
	 */
	@ResponseBody
	@PostMapping(value = "/article/recommend", produces = {"application/json;charset=UTF-8"})
	public Result recommend(){
		return articleService.recommend();
	}

	/**
	 * 搜索
	 * @param bean
	 * @return
	 */
    @ResponseBody
    @PostMapping(value = "/article/search", produces = {"application/json;charset=UTF-8"})
	public Result search(@RequestBody Article bean){
	    return articleService.search(bean);
    }

	/**
	 * 投稿
	 * @param bean
	 * @return
	 */
	@ResponseBody
	@PostMapping(value = "/article/submit", produces = {"application/json;charset=UTF-8"})
    public Result submit(@RequestBody Article bean){
    	return articleService.submit(bean);
	}

	/**
	 * 删除文章
	 * @param bean
	 * @return
	 */
	@ResponseBody
	@PostMapping(value = "/article/delete", produces = {"application/json;charset=UTF-8"})
	public Result delete(@RequestBody Article bean){
		return articleService.delete(bean);
	}

}
